import time
import os
import tkinter as tk
from tkinter import messagebox

# ===========================================================================
# Fake USB Payload Simulation and Educational Warning.
# This script simulates the execution of a malicious USB payload.
# It displays a terminal animation followed by a security warning pop-up.
# Created for educational purposes only.
# ===========================================================================

# --Function purpose: Simulate a fake USB payload execution in the terminal.--
def payload_simulation():

    # Clear the screen for cleaner look and feel
    os.system('cls' if os.name == 'nt' else 'clear')

    print("\n...USB Device Detected...")
    time.sleep(1)

    print("...Initializing payload...")
    time.sleep(1.2)

    # Fake 'payload stages'
    stages = [
        "Initializing payload",
        "Injecting runtime processes",
        "Retrieving stored credentials",
        "Deploying background services",
        "Triggering final execution phase",
    ]

    # Displays a loading bar for each stage
    for stage in stages:
        for i in range(1, 11):
            bar = "#" * i + "-" * (10 - i)
            print(f"\r{stage}: [{bar}] {i*10}%", end="")
            time.sleep(0.15)
        print() # New line after each stage is printed

    # Final 2 alert message in terminal before pop-up
    time.sleep(0.7)
    print("\n...Suspicious activity detected.")
    time.sleep(0.7)
    
    print("...Displaying educational safety message...")
    time.sleep(1.5)


# --Function purpose: Show a warning pop-up about USB security risks.--
def show_warning_popup():
    #Creates multi-line warning message
    message = """
⚠ SECURITY WARNING ⚠

You plugged in an unknown USB drive.

Attackers can use USB devices to:
• Steal your files
• Install malware
• Take control of your system
• Spread infections across a network

Stay safe by:
• Never using found USBs
• Reporting suspicious devices to IT
• Only connecting trusted hardware

This simulation is for educational purposes.
"""
    # Initialize Tkinter root and show warning message box
    root = tk.Tk()
    root.withdraw()
    # Show warning message box 
    messagebox.showwarning("USB Safety Notice", message)
    root.destroy()


# --Function purpose: Main function to run the payload simulation and show the warning pop-up.--
def main():
    payload_simulation()
    show_warning_popup()


# Script entry point
if __name__ == "__main__":
    main()

# =======================================================================================
# End of CNT4403_Answerkey.py
# =======================================================================================